package org.bultreebank.index.utils;

import org.w3c.dom.Document;

import clark.dtd.DTD;


public class Validator implements Constants
{
	public static boolean isConfigValid(String repositoryPath)
	throws Exception
	{
		DTD dtd = Utils.loadDTD(repositoryPath + CONFIG_DTD_PATH);
		Document configDoc = Utils.getDocumentFromString(Utils.getStringRepresentationOfFileContent(repositoryPath + CONFIG_DOC_PATH));
		return clark.validator.Validator.validateDocument(configDoc.getDocumentElement(),dtd, CONFIG_DOC_TYPE);
	}
	public static boolean isQueryValid(String repositoryPath, Document queryDoc)
	throws Exception
	{
		DTD dtd = Utils.loadDTD(repositoryPath + QUERY_DTD_PATH);
		return clark.validator.Validator.validateDocument(queryDoc.getDocumentElement(),dtd, "Query");
	}
	public static boolean isIndexSchemaValid(String repositoryPath, Document indexSchema,
			String docType)
	throws Exception
	{
		DTD dtd = Utils.loadDTD(repositoryPath + INDEX_SCHEMA_DTD_PATH);
		return clark.validator.Validator.validateDocument(indexSchema.getDocumentElement(),
				dtd, docType);
	}
	
}
